package com.joshua.spring.controller;

import com.joshua.spring.entity.JsonInfoDTO;
import com.joshua.spring.entity.vo.GlobalResponse;
import org.jasypt.encryption.StringEncryptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * description
 * package com.joshua.spring
 * classname  EncController
 *
 * @author <a href="mailto:joshualwork@163.com">joshua_liu</a>
 * @date 2020/4/24 15:20
 */
@RestController
@RequestMapping("jas")
public class EncController {
    @Autowired
    private StringEncryptor stringEncryptor;

    @GetMapping("enc")
    public GlobalResponse enc(@RequestParam String key) {
        return GlobalResponse.buildSuccess(stringEncryptor.encrypt(key));
    }

    @PostMapping("dec")
    public GlobalResponse dec(@RequestBody JsonInfoDTO dto) {
        return GlobalResponse.buildSuccess(stringEncryptor.decrypt(dto.getEncStr()));
    }
}
